# To track render durationstart_time <-Sys.time()# Install and load required packagesp_required <-c("tidyverse", #dplyr, ggplot, tibbles etc"here", # relative and sys agnostic file paths"janitor", # easy wrangling and exploratory tables"knitr", # kable()"ggpubr", # ggplot themes and shortcuts"scales","viridis","brms", # bayesian regression models using stan"sessioninfo"# documentation)packages <-rownames(installed.packages())p_to_install <- p_required[!(p_required %in% packages)]if (length(p_to_install) >0) { pak::pkg_install(p_to_install)}sapply(p_required, require, character.only =TRUE)
Loading required package: tidyverse
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Loading required package: here
here() starts at C:/R/research/CSAP
Loading required package: janitor
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
Loading required package: knitr
Loading required package: ggpubr
Loading required package: scales
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
Loading required package: viridis
Loading required package: viridisLite
Attaching package: 'viridis'
The following object is masked from 'package:scales':
viridis_pal
Loading required package: brms
Loading required package: Rcpp
Loading 'brms' package (version 2.23.0). Useful instructions
can be found by typing help('brms'). A more detailed introduction
to the package is available through vignette('brms_overview').
Attaching package: 'brms'
The following object is masked from 'package:stats':
ar
Loading required package: sessioninfo
Given our primary interest in explicit and implicit attachement, we pursue a maximizing strategy (i.e., for example, collapsing vote_intention and vote_intention_hypo)
Distribution of explicit and implicit partisan identities by country.
$Austria
der_pid Vote reported Don't know Other NA
Party ID reported 3774 192 6 6
No Party ID 2622 900 78 0
Other 48 6 24 0
NA 0 0 0 6
Total 6444 1098 108 12
$Belgium
der_pid Vote reported Don't know Other NA
Party ID reported 5040 210 36 6
No Party ID 1434 888 132 0
Other 24 12 42 0
NA 0 0 0 6
Total 6498 1110 210 12
$Bulgaria
der_pid Vote reported Don't know Other NA
Party ID reported 2520 168 102 0
No Party ID 1548 918 450 0
Other 114 18 48 0
NA 0 0 0 6
Total 4182 1104 600 6
$Croatia
der_pid Vote reported Don't know Other NA
Party ID reported 3102 348 336 0
No Party ID 1320 1554 420 0
Other 126 12 216 0
NA 0 0 0 6
Total 4548 1914 972 6
$`Czech Republic`
der_pid Vote reported Don't know Other NA
Party ID reported 4236 546 60 6
No Party ID 828 966 72 0
Other 18 6 60 0
NA 0 0 0 12
Total 5082 1518 192 18
$Denmark
der_pid Vote reported Don't know Other NA
Party ID reported 5568 360 72 6
No Party ID 540 444 48 0
Other 66 54 36 0
NA 0 0 0 6
Total 6174 858 156 12
$Estonia
der_pid Vote reported Don't know Other NA
Party ID reported 3120 72 126 0
No Party ID 1728 324 204 0
Other 60 0 18 0
NA 0 0 0 12
Total 4908 396 348 12
$Finland
der_pid Vote reported Don't know Other NA
Party ID reported 4068 204 72 18
No Party ID 1284 972 156 6
Other 60 12 102 0
NA 0 0 0 6
Total 5412 1188 330 30
$France
der_pid Vote reported Don't know Other NA
Party ID reported 4176 180 54 36
No Party ID 1110 1194 150 0
Other 6 12 0 0
NA 0 0 0 18
Total 5292 1386 204 54
$Germany
der_pid Vote reported Don't know Other NA
Party ID reported 3666 90 132 174
No Party ID 1764 948 222 66
Other 6 6 54 0
NA 0 0 0 0
Total 5436 1044 408 240
$Greece
der_pid Vote reported Don't know Other NA
Party ID reported 3894 222 72 6
No Party ID 1194 912 198 0
Other 222 48 192 0
NA 0 0 0 6
Total 5310 1182 462 12
$Hungary
der_pid Vote reported Don't know Other NA
Party ID reported 3642 168 24 0
No Party ID 1134 708 144 0
Other 48 6 42 0
NA 0 0 0 0
Total 4824 882 210 0
$Ireland
der_pid Vote reported Don't know Other NA
Party ID reported 2916 120 48 0
No Party ID 2016 1032 144 0
Other 48 0 36 0
NA 0 0 0 6
Total 4980 1152 228 6
$Italy
der_pid Vote reported Don't know Other NA
Party ID reported 4950 366 30 0
No Party ID 618 900 84 0
Other 24 6 36 0
NA 0 0 0 18
Total 5592 1272 150 18
$Latvia
der_pid Vote reported Don't know Other NA
Party ID reported 2346 174 156 0
No Party ID 2652 1062 378 0
Other 66 12 36 0
NA 0 0 0 6
Total 5064 1248 570 6
$Lithuania
der_pid Vote reported Don't know Other NA
Party ID reported 3132 192 24 0
No Party ID 2724 1122 192 0
Other 138 18 48 0
NA 0 0 0 0
Total 5994 1332 264 0
$Netherlands
der_pid Vote reported Don't know Other NA
Party ID reported 4704 270 54 0
No Party ID 1182 948 96 0
Other 18 6 36 0
NA 0 0 0 12
Total 5904 1224 186 12
$Poland
der_pid Vote reported Don't know Other NA
Party ID reported 4950 240 0 0
No Party ID 1242 690 24 0
Other 30 0 6 0
NA 0 0 0 6
Total 6222 930 30 6
$Portugal
der_pid Vote reported Don't know Other NA
Party ID reported 3672 498 216 0
No Party ID 1068 1218 288 0
Other 24 18 102 0
NA 6 4 0 0
Total 4770 1738 606 0
$Romania
der_pid Vote reported Don't know Other NA
Party ID reported 4614 186 126 6
No Party ID 2316 1128 300 0
Other 54 36 78 0
NA 8 0 0 10
Total 6992 1350 504 16
$Slovakia
der_pid Vote reported Don't know Other NA
Party ID reported 4104 306 126 0
No Party ID 1632 1350 132 0
Other 72 12 48 0
NA 0 0 0 0
Total 5808 1668 306 0
$Slovenia
der_pid Vote reported Don't know Other NA
Party ID reported 3798 348 132 0
No Party ID 1224 942 210 0
Other 54 6 60 0
NA 0 0 0 36
Total 5076 1296 402 36
$Spain
der_pid Vote reported Don't know Other NA
Party ID reported 5688 186 54 6
No Party ID 1386 786 96 6
Other 78 24 54 0
NA 0 0 0 12
Total 7152 996 204 24
$Sweden
der_pid Vote reported Don't know Other NA
Party ID reported 5274 270 78 0
No Party ID 966 696 96 0
Other 48 6 78 0
NA 0 0 0 12
Total 6288 972 252 12
$`United Kingdom`
der_pid Vote reported Don't know Other NA
Party ID reported 4548 264 36 18
No Party ID 1872 798 84 0
Other 12 0 24 0
NA 0 0 0 18
Total 6432 1062 144 36
Overview of data distribution
Respondents -> Party ID -> Vote report
In words, respondents either report a partisan identity (i.e., a felt attachement to a political party) or they deny the presence of such feelings.
# A tibble: 3 × 2
pid_equal_vote_id n
<dbl> <int>
1 0 3626
2 1 12437
3 NA 2294
In [21]:
Code
eu25games2019 <- eu25games2019 |>mutate(pid_equal_vote_id =case_when( der_pid =="Party ID reported"& der_vote_cat =="Vote reported"& der_vote_combined_id == ext_q_party_id_pf_id ~1, der_pid =="Party ID reported"& der_vote_cat =="Vote reported"& der_vote_combined_id != ext_q_party_id_pf_id ~0,.default =NA ),pid_equal_vote_name =case_when( der_pid =="Party ID reported"& der_vote_cat =="Vote reported"& der_vote_combined_name == ext_q_party_id_pf_name ~1, der_pid =="Party ID reported"& der_vote_cat =="Vote reported"& der_vote_combined_name != ext_q_party_id_pf_name ~0,.default =NA ) )# manually recode some instances where the casewhen check above yielded different but inspection revealed its basically the same partyeu25games2019 <- eu25games2019 |>mutate(# New column using case_when for manual line-by-line recodingpid_equal_vote_name2 =case_when(# Case 1: Party names are already identical (from pid_equal_vote_name = 1) pid_equal_vote_name ==1~1,# Case 2: Polish Koalicja Obywatelska (PO, SLD, Spring, PSL, Nowoczesna) pid_equal_vote_name ==0& ext_q_party_id_pf_name %in%c("Platforma Obywatelska","Sojusz Lewicy Demokratycznej","Spring","Polskie Stronnictwo Ludowe","Nowoczesna" ) & der_vote_combined_name =="Koalicja Obywatelska"~1,# Case 3: Spanish Unidas Podemos (Podemos, Izquierda Unida) pid_equal_vote_name ==0& ext_q_party_id_pf_name %in%c("Podemos","Izquierda Unida" ) & der_vote_combined_name =="Unidas Podemos"~1,# Case 4: Dutch ChristenUnie — SGP pid_equal_vote_name ==0& ext_q_party_id_pf_name %in%c("ChristenUnie","Staatkundig Gereformeerde Partij" ) & der_vote_combined_name =="ChristenUnie — Staatkundig Gereformeerde Partij"~1,# Case 5: Hungarian Fidesz — KDNP (using grepl for robustness against long name) pid_equal_vote_name ==0& ext_q_party_id_pf_name %in%c("Fidesz — Magyar Polgári Szövetség","Kereszténydemokrata Néppárt" ) &grepl("Fidesz — KDNP pártszövetség", der_vote_combined_name,fixed =TRUE ) ~1,# Case 6: Polish Konfederacja Wolność i Niepodległość (KNP, KORWiN, Kukiz'15) pid_equal_vote_name ==0& ext_q_party_id_pf_name %in%c("Kongres Nowej Prawicy","Koalicja Odnowy Rzeczypospolitej Wolność i Nadzieja KORWiN","Kukiz'15" ) & der_vote_combined_name =="Konfederacja Wolność i Niepodległość"~1,# Case 7: Latvian Attīstībai/Par! pid_equal_vote_name ==0& ext_q_party_id_pf_name =="Kustība Par!"& der_vote_combined_name =="Attīstībai/Par!"~1,# Case 8: French LREM/Renaissance pid_equal_vote_name ==0& ext_q_party_id_pf_name =="Mouvement démocrate"& der_vote_combined_name =="La République En Marche! / Renaissance"~1,# Case 9: Catalan JxCat (Partit Demòcrata Europeu Català) pid_equal_vote_name ==0& ext_q_party_id_pf_name =="Partit Demòcrata Europeu Català"& der_vote_combined_name =="Junts per Catalunya — Partit Demòcrata Europeu Català"~1,# Default: All other cases (where pid_equal_vote_name was 0 and no manual case matched)TRUE~ pid_equal_vote_name ) )eu25games2019 |>distinct(meta_pid, .keep_all = T) |>count(pid_equal_vote_name2)
# A tibble: 3 × 2
pid_equal_vote_name2 n
<dbl> <int>
1 0 3697
2 1 13220
3 NA 12910
Schematic overview
In [22]:
Code
flowchart TD A(Respondents <br> N = 29,827) --> B(No Party ID <br> N = 10,880) A(Respondents <br> N = 29,827) --> C(Party ID <br> N = 18,357) B --> D(No Vote <br> N = 3,900) B --> E(Vote <br> N = 6,234) C --> F(No Vote <br> N = 1,030) C --> G(Vote <br> N = 16,917) G --> H(Same as PID <br> N = 13,220) G --> I(Diff from PID <br> N = 3,697)
flowchart TD
A(Respondents <br> N = 29,827) --> B(No Party ID <br> N = 10,880)
A(Respondents <br> N = 29,827) --> C(Party ID <br> N = 18,357)
B --> D(No Vote <br> N = 3,900)
B --> E(Vote <br> N = 6,234)
C --> F(No Vote <br> N = 1,030)
C --> G(Vote <br> N = 16,917)
G --> H(Same as PID <br> N = 13,220)
G --> I(Diff from PID <br> N = 3,697)
# A tibble: 179 × 4
meta_country der_nopid der_vote_cat n
<chr> <dbl> <fct> <int>
1 Austria 0 Vote reported 3822
2 Austria 0 Don't know 198
3 Austria 0 Other 30
4 Austria 0 NA 6
5 Austria 1 Vote reported 2622
6 Austria 1 Don't know 900
7 Austria 1 Other 78
8 Austria 1 NA 6
9 Belgium 0 Vote reported 5064
10 Belgium 0 Don't know 222
# ℹ 169 more rows
Code
total_counts <- df_reshaped |>group_by(meta_country, der_nopid) |>summarise(n =sum(n), .groups ="drop") |>mutate(nopid2 =if_else(der_nopid ==1, "No PID", "PID"),toprint =paste0( nopid2,"\n",as.character(n) ),toprint2 =as.character(n) )ggplot(df_reshaped, aes(x =as.factor(der_nopid), y = n, fill = der_vote_cat)) +geom_col() +geom_text(data = total_counts,aes(label = toprint2, fill ="black"),vjust =if_else( total_counts$der_nopid ==1,0,1 ),size =3 ) +facet_wrap(~meta_country) +labs(y ="N", x ="") +scale_x_discrete(labels =c("0"="PID", "1"="No PID")) +scale_fill_manual(values =c("Don't know"="darkgray","NA"="black","Other"="orange","Vote reported"="gold" ) ) +theme_pubr()
Warning in geom_text(data = total_counts, aes(label = toprint2, fill =
"black"), : Ignoring unknown aesthetics: fill
Distribution of Reported Partisan Affiliation and Vote Choice/Intention across included European countries.
Comparing levels of affective polarization between explicit and implicit partisans
In [24]:
Code
# what to do: estimate aff pol model separately or interaction term?# preferred choice: create variable storing the different factor levels,# allows direct comparison and inclusion of all cases in model# wait I need 2 steps: 1 variable storing the type of partisanship,# and 1 mapping the conjoint profiles# create implicit/explicit partisan marker variableeu25games2019 <- eu25games2019 |>mutate(# combined variable for partisanshipder_partisanship =case_when( der_pid =="Party ID reported"~"1_pid_expl", der_pid =="No Party ID"& der_vote_cat =="Vote reported"~"2_pid_impl", der_pid =="No Party ID"& der_vote_cat =="Don't know"~"3_nopid", der_pid =="No Party ID"& der_vote_cat =="NA"~"3_nopid", der_pid =="NA"& der_vote_cat =="Vote reported"~"2_pid_impl", der_pid =="NA"& der_vote_cat =="Don't know"~"3_nopid", der_pid =="NA"& der_vote_cat =="NA"~"3_nopid" ) )# now let's create a new co/outpartisan variable including implicit partisans tooeu25games2019 <- eu25games2019 |>mutate(der_outpartisan_comb =case_when(# === EXPLICIT PID =======================================================# case 1: pid and control group (implies conational) der_partisanship =="1_pid_expl"& cj_trmnt =="4_somenat"& der_conational =="co-national"~"1_control_expl",# case 2: pid and copartisan (same) der_partisanship =="1_pid_expl"&str_detect(cj_trmnt, "partisan") & (ext_cj_party_pf_name == ext_q_party_id_pf_name) ~"2_co_expl",# case 3: pid and outpartisan der_partisanship =="1_pid_expl"&str_detect(cj_trmnt, "partisan") & (ext_cj_party_pf_name != ext_q_party_id_pf_name) ~"3_out_expl",# case 4: pid and eu outnational cj (hence no party shown) der_partisanship =="1_pid_expl"&!str_detect(cj_trmnt, "partisan") &str_detect(cj_trmnt, "eunat") ~"97_eunat_expl",# case 5: pid and noneu outnational cj (hence no party shown) der_partisanship =="1_pid_expl"&!str_detect(cj_trmnt, "partisan") &str_detect(cj_trmnt, "somenat") ~"98_outnat_expl",# === IMPLICIT PID =======================================================# case 4: pid and control group der_partisanship =="2_pid_impl"& cj_trmnt =="4_somenat"& der_conational =="co-national"~"4_control_impl",# case 5: impl pid and copartisan der_partisanship =="2_pid_impl"&str_detect(cj_trmnt, "partisan") & (ext_cj_party_pf_name == der_vote_combined_name) ~"5_co_impl",# case 6: pid and outpartisan der_partisanship =="2_pid_impl"&str_detect(cj_trmnt, "partisan") & (ext_cj_party_pf_name != der_vote_combined_name) ~"6_out_impl",# case 4: pid and eu outnational cj (hence no party shown) der_partisanship =="2_pid_impl"&!str_detect(cj_trmnt, "partisan") &str_detect(cj_trmnt, "eunat") ~"97_eunat_impl",# case 5: pid and noneu outnational cj (hence no party shown) der_partisanship =="2_pid_impl"&!str_detect(cj_trmnt, "partisan") &str_detect(cj_trmnt, "somenat") ~"98_outnat_impl",# === NO PID ============================================================= der_partisanship =="3_nopid"& cj_trmnt =="4_somenat"& der_conational =="co-national"~"7_control_nopid", der_partisanship =="3_nopid"&str_detect(cj_trmnt, "partisan") ~"8_ptycue_nopid", der_partisanship =="3_nopid"& der_conational =="out-national-EU"~"99_outnatEU_nopid", der_partisanship =="3_nopid"& der_conational =="out-national-non-EU"~"99_outnat_nopid",.default =NA ) )labels_der_outpartisan_comb <- eu25games2019 |>distinct(der_outpartisan_comb) |>mutate()
Distribution of partisan types, by country. Stacked horizontal bars show the within-country share (%) of three partisan types: explicit partisans (respondents who reported a subjective attachement to a party, \(T_i=1\)), implicit partisans (respondents who reported no attachement but did report a vote preference or intention, \(T_i=0\)), and respondents who reported neither (none, \(T_i = \emptyset\)). Percentages sum to 100% within each country, with country samples containing about \(1,100\) respondents each (detailed numbers are reported in appendix section X).
Exploratory analysis of country specific ingroup and outgroup dynamics by partisan type
`summarise()` has grouped output by 'meta_country'. You can override using the
`.groups` argument.
Code
token_means_pooled <- eu25games2019 |>filter(meta_game =="dict") |>filter(!der_outpartisan_comb %in%c("97_eunat_expl","97_eunat_impl","98_outnat_expl","98_outnat_impl","99_outnatEU_nopid","99_outnat_nopid" ) &!is.na(der_outpartisan_comb) ) |>group_by(der_outpartisan_comb) |>summarise(m =mean(cj_token_logged),s =sd(cj_token_logged),n =n() ) |>ungroup()token_means_pooled <- token_means_pooled |>mutate(meta_country ="Pooled") |>select(meta_country, der_outpartisan_comb, m, s, n)token_means <- token_means |>bind_rows(token_means_pooled)qoi_bycountry <- token_means |>group_by(meta_country) |>summarise(# Explicit Conditions (expl_Type_Stat)# IF_expl: Difference (2 - 1)expl_IF_diff = m[der_outpartisan_comb =="2_co_expl"] - m[der_outpartisan_comb =="1_control_expl"],expl_IF_SE =sqrt( (s[der_outpartisan_comb =="2_co_expl"]^2/ n[der_outpartisan_comb =="2_co_expl"]) + (s[der_outpartisan_comb =="1_control_expl"]^2/ n[der_outpartisan_comb =="1_control_expl"]) ),expl_IF_CI_LOWER = expl_IF_diff -1.96* expl_IF_SE,expl_IF_CI_UPPER = expl_IF_diff +1.96* expl_IF_SE,# OD_expl: Difference (1 - 3)expl_OD_diff = m[der_outpartisan_comb =="1_control_expl"] - m[der_outpartisan_comb =="3_out_expl"],expl_OD_SE =sqrt( (s[der_outpartisan_comb =="1_control_expl"]^2/ n[der_outpartisan_comb =="1_control_expl"]) + (s[der_outpartisan_comb =="3_out_expl"]^2/ n[der_outpartisan_comb =="3_out_expl"]) ),expl_OD_CI_LOWER = expl_OD_diff -1.96* expl_OD_SE,expl_OD_CI_UPPER = expl_OD_diff +1.96* expl_OD_SE,# AP_expl: Difference (2 - 3)expl_AP_diff = m[der_outpartisan_comb =="2_co_expl"] - m[der_outpartisan_comb =="3_out_expl"],expl_AP_SE =sqrt( (s[der_outpartisan_comb =="2_co_expl"]^2/ n[der_outpartisan_comb =="2_co_expl"]) + (s[der_outpartisan_comb =="3_out_expl"]^2/ n[der_outpartisan_comb =="3_out_expl"]) ),expl_AP_CI_LOWER = expl_AP_diff -1.96* expl_AP_SE,expl_AP_CI_UPPER = expl_AP_diff +1.96* expl_AP_SE,# Implicit Conditions (impl_Type_Stat)# IF_impl: Difference (5 - 4)impl_IF_diff = m[der_outpartisan_comb =="5_co_impl"] - m[der_outpartisan_comb =="4_control_impl"],impl_IF_SE =sqrt( (s[der_outpartisan_comb =="5_co_impl"]^2/ n[der_outpartisan_comb =="5_co_impl"]) + (s[der_outpartisan_comb =="4_control_impl"]^2/ n[der_outpartisan_comb =="4_control_impl"]) ),impl_IF_CI_LOWER = impl_IF_diff -1.96* impl_IF_SE,impl_IF_CI_UPPER = impl_IF_diff +1.96* impl_IF_SE,# OD_impl: Difference (4 - 6)impl_OD_diff = m[der_outpartisan_comb =="4_control_impl"] - m[der_outpartisan_comb =="6_out_impl"],impl_OD_SE =sqrt( (s[der_outpartisan_comb =="4_control_impl"]^2/ n[der_outpartisan_comb =="4_control_impl"]) + (s[der_outpartisan_comb =="6_out_impl"]^2/ n[der_outpartisan_comb =="6_out_impl"]) ),impl_OD_CI_LOWER = impl_OD_diff -1.96* impl_OD_SE,impl_OD_CI_UPPER = impl_OD_diff +1.96* impl_OD_SE,# AP_impl: Difference (5 - 6)impl_AP_diff = m[der_outpartisan_comb =="5_co_impl"] - m[der_outpartisan_comb =="6_out_impl"],impl_AP_SE =sqrt( (s[der_outpartisan_comb =="5_co_impl"]^2/ n[der_outpartisan_comb =="5_co_impl"]) + (s[der_outpartisan_comb =="6_out_impl"]^2/ n[der_outpartisan_comb =="6_out_impl"]) ),impl_AP_CI_LOWER = impl_AP_diff -1.96* impl_AP_SE,impl_AP_CI_UPPER = impl_AP_diff +1.96* impl_AP_SE,# None Condition (none_Type_Stat)# OD_none: Difference (7 - 8)none_OD_diff = m[der_outpartisan_comb =="7_control_nopid"] - m[der_outpartisan_comb =="8_ptycue_nopid"],none_OD_SE =sqrt( (s[der_outpartisan_comb =="7_control_nopid"]^2/ n[der_outpartisan_comb =="7_control_nopid"]) + (s[der_outpartisan_comb =="8_ptycue_nopid"]^2/ n[der_outpartisan_comb =="8_ptycue_nopid"]) ),none_OD_CI_LOWER = none_OD_diff -1.96* none_OD_SE,none_OD_CI_UPPER = none_OD_diff +1.96* none_OD_SE )tidy_qoi <- qoi_bycountry |># 1. Pivot the data from wide to long formatpivot_longer(# Select all columns except the grouping variablecols =-meta_country,# 2. Split the column names into three parts: Condition, Type, and Valuenames_to =c("pid_type_raw", "diff_type", ".value"),# 3. Define the pattern for separation (Condition_Type_Statistic)names_pattern ="(expl|impl|none)_([A-Z]+)_(diff|SE|CI_LOWER|CI_UPPER)$"# Explanation:# (expl|impl|none) -> Captures the Condition into 'pid_type_raw'# ([A-Z]+) -> Captures the Type (IF, OD, AP) into 'diff_type'# (diff|SE|CI_LOWER|CI_UPPER) -> Captures the Statistic into '.value' (creating columns diff, SE, CI_LOWER, CI_UPPER) ) |># 4. Clean up the pid_type and rename the 'diff' columnmutate(pid_type =case_match( pid_type_raw,"expl"~"explicit","impl"~"implicit","none"~"none" ) ) |>rename(Difference = diff ) |># 5. Select and reorder final columns for readabilityselect( meta_country, pid_type, diff_type, Difference, SE,starts_with("CI_") )plot_data <- tidy_qoi |>mutate(country_condition =paste(meta_country, pid_type, sep =" | "),country_condition =fct_inorder(country_condition) ) |>mutate(# extract pooled levelscountry_condition =fct_relevel( country_condition,grep("^Pooled \\|", levels(country_condition), value =TRUE),after =Inf# use 0 for top, Inf for bottom ),country_condition =fct_rev(country_condition),diff_type =factor(diff_type, levels =c("IF", "OD", "AP")) )# 2. Create the Plotggplot( plot_data,aes(y = country_condition,x = Difference,shape = pid_type,color = meta_country )) +# Add the vertical line at zero (to check for significance)geom_vline(xintercept =0, linetype ="dashed", color ="red", alpha =0.6) +# Add the Confidence Intervals (horizontal error bars)geom_errorbarh(aes(xmin = CI_LOWER, xmax = CI_UPPER),height =0.2,linewidth =0.5 ) +# Add the point estimategeom_point(size =2.5) +# Crucial Step: Facet the plot horizontally by the Difference Type (IF, OD, AP)facet_wrap(~diff_type,ncol =3,scales ="free_x"# Allow x-axis to scale independently for each difference type ) +# Labels and theminglabs(y ="Country | PID Type",x ="Mean Difference (Point Estimate with 95% CI)" ) +theme_pubr() +scale_color_manual(values =c(rep(c("#648FFF","#DC267F","#785EF0","#FE6100","#FFB000" ),5 ),"black" ) ) +theme(# Reduce font size for Y-axis labels if they are too longaxis.text.y =element_text(size =8, hjust =0),# Ensure facet titles are clearstrip.text =element_text(face ="bold"),legend.position ="none" )
Exploratory token allocation behavior by country and pid type in the dictator game: ingroup favoritism, outgroup derogation and affective polarization. The figure shows mean differences in token allocation with 95% confidence intervals. IF = mean(token2co) - mean(token2control), OD = mean(token2control) - mean(token2out), AP = mean(token2co) - mean(token2out)
`summarise()` has grouped output by 'meta_country'. You can override using the
`.groups` argument.
Code
qoi_bycountry <- token_means |>group_by(meta_country) |>summarise(# Explicit Conditions (expl_Type_Stat)# IF_expl: Difference (2 - 1)expl_IF_diff = m[der_outpartisan_comb =="2_co_expl"] - m[der_outpartisan_comb =="1_control_expl"],expl_IF_SE =sqrt( (s[der_outpartisan_comb =="2_co_expl"]^2/ n[der_outpartisan_comb =="2_co_expl"]) + (s[der_outpartisan_comb =="1_control_expl"]^2/ n[der_outpartisan_comb =="1_control_expl"]) ),expl_IF_CI_LOWER = expl_IF_diff -1.96* expl_IF_SE,expl_IF_CI_UPPER = expl_IF_diff +1.96* expl_IF_SE,# OD_expl: Difference (1 - 3)expl_OD_diff = m[der_outpartisan_comb =="1_control_expl"] - m[der_outpartisan_comb =="3_out_expl"],expl_OD_SE =sqrt( (s[der_outpartisan_comb =="1_control_expl"]^2/ n[der_outpartisan_comb =="1_control_expl"]) + (s[der_outpartisan_comb =="3_out_expl"]^2/ n[der_outpartisan_comb =="3_out_expl"]) ),expl_OD_CI_LOWER = expl_OD_diff -1.96* expl_OD_SE,expl_OD_CI_UPPER = expl_OD_diff +1.96* expl_OD_SE,# AP_expl: Difference (2 - 3)expl_AP_diff = m[der_outpartisan_comb =="2_co_expl"] - m[der_outpartisan_comb =="3_out_expl"],expl_AP_SE =sqrt( (s[der_outpartisan_comb =="2_co_expl"]^2/ n[der_outpartisan_comb =="2_co_expl"]) + (s[der_outpartisan_comb =="3_out_expl"]^2/ n[der_outpartisan_comb =="3_out_expl"]) ),expl_AP_CI_LOWER = expl_AP_diff -1.96* expl_AP_SE,expl_AP_CI_UPPER = expl_AP_diff +1.96* expl_AP_SE,# Implicit Conditions (impl_Type_Stat)# IF_impl: Difference (5 - 4)impl_IF_diff = m[der_outpartisan_comb =="5_co_impl"] - m[der_outpartisan_comb =="4_control_impl"],impl_IF_SE =sqrt( (s[der_outpartisan_comb =="5_co_impl"]^2/ n[der_outpartisan_comb =="5_co_impl"]) + (s[der_outpartisan_comb =="4_control_impl"]^2/ n[der_outpartisan_comb =="4_control_impl"]) ),impl_IF_CI_LOWER = impl_IF_diff -1.96* impl_IF_SE,impl_IF_CI_UPPER = impl_IF_diff +1.96* impl_IF_SE,# OD_impl: Difference (4 - 6)impl_OD_diff = m[der_outpartisan_comb =="4_control_impl"] - m[der_outpartisan_comb =="6_out_impl"],impl_OD_SE =sqrt( (s[der_outpartisan_comb =="4_control_impl"]^2/ n[der_outpartisan_comb =="4_control_impl"]) + (s[der_outpartisan_comb =="6_out_impl"]^2/ n[der_outpartisan_comb =="6_out_impl"]) ),impl_OD_CI_LOWER = impl_OD_diff -1.96* impl_OD_SE,impl_OD_CI_UPPER = impl_OD_diff +1.96* impl_OD_SE,# AP_impl: Difference (5 - 6)impl_AP_diff = m[der_outpartisan_comb =="5_co_impl"] - m[der_outpartisan_comb =="6_out_impl"],impl_AP_SE =sqrt( (s[der_outpartisan_comb =="5_co_impl"]^2/ n[der_outpartisan_comb =="5_co_impl"]) + (s[der_outpartisan_comb =="6_out_impl"]^2/ n[der_outpartisan_comb =="6_out_impl"]) ),impl_AP_CI_LOWER = impl_AP_diff -1.96* impl_AP_SE,impl_AP_CI_UPPER = impl_AP_diff +1.96* impl_AP_SE,# None Condition (none_Type_Stat)# OD_none: Difference (7 - 8)none_OD_diff = m[der_outpartisan_comb =="7_control_nopid"] - m[der_outpartisan_comb =="8_ptycue_nopid"],none_OD_SE =sqrt( (s[der_outpartisan_comb =="7_control_nopid"]^2/ n[der_outpartisan_comb =="7_control_nopid"]) + (s[der_outpartisan_comb =="8_ptycue_nopid"]^2/ n[der_outpartisan_comb =="8_ptycue_nopid"]) ),none_OD_CI_LOWER = none_OD_diff -1.96* none_OD_SE,none_OD_CI_UPPER = none_OD_diff +1.96* none_OD_SE )tidy_qoi <- qoi_bycountry |># 1. Pivot the data from wide to long formatpivot_longer(# Select all columns except the grouping variablecols =-meta_country,# 2. Split the column names into three parts: Condition, Type, and Valuenames_to =c("pid_type_raw", "diff_type", ".value"),# 3. Define the pattern for separation (Condition_Type_Statistic)names_pattern ="(expl|impl|none)_([A-Z]+)_(diff|SE|CI_LOWER|CI_UPPER)$"# Explanation:# (expl|impl|none) -> Captures the Condition into 'pid_type_raw'# ([A-Z]+) -> Captures the Type (IF, OD, AP) into 'diff_type'# (diff|SE|CI_LOWER|CI_UPPER) -> Captures the Statistic into '.value' (creating columns diff, SE, CI_LOWER, CI_UPPER) ) |># 4. Clean up the pid_type and rename the 'diff' columnmutate(pid_type =case_match( pid_type_raw,"expl"~"explicit","impl"~"implicit","none"~"none" ) ) |>rename(Difference = diff ) |># 5. Select and reorder final columns for readabilityselect( meta_country, pid_type, diff_type, Difference, SE,starts_with("CI_") )# 1. Prepare the data for plottingplot_data <- tidy_qoi |># Create a single factor combining country and condition for the Y-axismutate(# Combine country and pid_type into one label (e.g., "Austria | explicit")country_condition =factor(paste(meta_country, pid_type, sep =" | ")),# Use fct_inorder to maintain the logical order (country-by-country)# Then fct_rev reverses the entire factor so the first country appears at the top of the Y-axiscountry_condition =fct_rev(fct_inorder(country_condition)) ) |># Optional: Clean up diff_type for better facet labelsmutate(diff_type =factor(diff_type, levels =c("IF", "OD", "AP")) )# 2. Create the Plotggplot( plot_data,aes(y = country_condition,x = Difference,shape = pid_type,color = meta_country )) +# Add the vertical line at zero (to check for significance)geom_vline(xintercept =0, linetype ="dashed", color ="red", alpha =0.6) +# Add the Confidence Intervals (horizontal error bars)geom_errorbarh(aes(xmin = CI_LOWER, xmax = CI_UPPER),height =0.2,linewidth =0.5 ) +# Add the point estimategeom_point(size =2.5) +# Crucial Step: Facet the plot horizontally by the Difference Type (IF, OD, AP)facet_wrap(~diff_type,ncol =3,scales ="free_x"# Allow x-axis to scale independently for each difference type ) +# Labels and theminglabs(y ="Country | PID Type",x ="Mean Difference (Point Estimate with 95% CI)" ) +theme_pubr() +scale_color_manual(values =rep(c("#648FFF","#DC267F","#785EF0","#FE6100","#FFB000" ),5 ) ) +theme(# Reduce font size for Y-axis labels if they are too longaxis.text.y =element_text(size =8, hjust =0),# Ensure facet titles are clearstrip.text =element_text(face ="bold"),legend.position ="none" )
Exploratory token allocation behavior by country and pid type in the trust game: ingroup favoritism, outgroup derogation and affective polarization. The figure shows mean differences in token allocation with 95% confidence intervals. IF = mean(token2co) - mean(token2control), OD = mean(token2control) - mean(token2out), AP = mean(token2co) - mean(token2out)
# think of it as partisan ingroupeu25games2019 <- eu25games2019 |>mutate(der_partisan_anchor =case_when( der_pid =="Party ID reported"~ ext_q_party_id_pf_name, der_pid =="No Party ID"& der_vote_cat =="Vote reported"~ der_vote_combined_name ) )# how many anchors in data?eu25games2019 |>distinct(der_partisan_anchor) |>na.omit() |>nrow()
[1] 374
Code
# same if grouped by country?eu25games2019 |>group_by(meta_country) |>distinct(der_partisan_anchor) |>na.omit() |>nrow()
der_partisan_anchor n percent valid_percent
Die Grünen — Die grüne Alternative 834 0.1 0.1
EU-Austrittspartei (EUAUS)[og] 42 0.0 0.0
EUROPA Jetzt – Initiative Johannes Voggenhuber[og] 60 0.0 0.0
Freiheitliche Partei Österreichs 1470 0.2 0.2
KPÖ Plus – European Left, offene Liste[og] 60 0.0 0.0
Kommunistische Partei Österreichs 84 0.0 0.0
Liste Peter Pilz 78 0.0 0.0
NEOS — Das Neue Österreich 696 0.1 0.1
Piraten[og] 30 0.0 0.0
Sozialdemokratische Partei Österreichs 1620 0.2 0.2
Österreichische Volkspartei 1626 0.2 0.2
<NA> 1062 0.1 NA
Total 7662 1.0 1.0